if [[ $# -eq 0 ]];then
        echo "No Image Input"
        exit 2
fi

# 本地仓库地址
local_repo_path="/Users/fzh/www/file-storage"
# 远程Git仓库链接
origin_repo_path="https://gitee.com/yywxf/file-storage.git"
# 仓库目录
origin_dir="imgs"

# 文件生成地址
origin_pre_path="${origin_repo_path%.*}/raw/master/${origin_dir}/"

cd $local_repo_path

# 拷贝图片到本地git仓库并打印链接
img_path=""
while [[ $# -gt 0 ]]
do
        path_raw=$1
        img_path=$path_raw
        shift
        
        # 判断是否是完整路径（可能含有空格）
        img_type=${path_raw##*.}
        while [[ $# -gt 0 && "${img_type}" != "jpg" && "${img_type}" != "jpeg" && "${img_type}" != "png" && "${img_type}" != "bmp" && "${img_type}" != "gif" && "${img_type}" != "tiff" && "${img_type}" != "svg" ]]
        do
                img_path="$img_path $1"
                img_type=${img_path##*.}
                shift
        done
        
        # 拷贝
        cp "$img_path" "./${origin_dir}/"

        # 打印图片链接
        echo ${origin_pre_path}${img_path##*[\\\/]}
        img_path=""
done

# 上传到远程仓库
git add imgs
git commit -m "upload image"
git push
